package com.techsen.tsweb.sys.domain;

import com.techsen.tsweb.core.domain.TreeNode;
import com.techsen.tsweb.sys.security.AclPermission;
import com.techsen.tsweb.sys.security.Resource;

/**
 * 菜单
 */
public class Menu extends TreeNode<Menu> implements Resource {

    private static final long serialVersionUID = 3243352830661169228L;
    
    /**
     * 菜单名
     */
    private String name;
    
    /**
     * 菜单路径
     */
    private String path;
    
    /**
     * ACL索引
     */
    private Integer aclIndex;
    
    /**
     * 排序号
     */
    private Double order;
    
    public String getName() {
        return name;
    }

    public Menu setName(String name) {
        this.name = name;
        return this;
    }

    public String getPath() {
        return path;
    }

    public Menu setPath(String path) {
        this.path = path;
        return this;
    }

    public Integer getAclIndex() {
        return aclIndex;
    }

    public Menu setAclIndex(Integer aclIndex) {
        this.aclIndex = aclIndex;
        return this;
    }

    public Double getOrder() {
        return order;
    }

    public Menu setOrder(Double order) {
        this.order = order;
        return this;
    }

    /**
     * 资源类型
     */
    @Override
    public String getResourceType() {
        return this.getClass().getSimpleName().toLowerCase();
    }

    /**
     * 所属资源组
     */
    @Override
    public String getResourceGroup() {
        return this.getParentId();
    }

    /**
     * 资源标识
     */
    @Override
    public String getResourceSn() {
        return this.id;
    }

    /**
     * 访问控制码
     */
    @Override
    public Integer getAclCode() {
        return aclIndex == null ? AclPermission.NONE_PERMISSION_TOKEN : 1 << aclIndex;
    }

}
